<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ include file="../../../attr.jsp" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<!doctype html>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=emulateIE7" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta charset="utf-8">
<link rel="stylesheet" href="${ctx}/css/sapar.css" />
<link rel="stylesheet" type="text/css" href="${ctx}/css/common.css" />
<link rel="stylesheet" type="text/css" href="${ctx}/css/kkpager_blue.css" />
<script type="text/javascript" src="${ctx}/js/jquery.js"></script>
<script type="text/javascript" src="${ctx}/js/sapar.js"></script>
<script type="text/javascript" src="${ctx}/js/WdatePicker.js"></script>
<script type="text/javascript" src="${ctx}/assets/layer/layer.js"></script>
<script type="text/javascript" src="${ctx}/js/kkpager.min.js"></script>

<style>
.buttons{
margin-left:30px;
}
#ddd{
float:left;
}
th{
text-align:center;
}
td{
text-align:center;
}
.buttons{
margin-left: 50px;
}
#fff{
margin-left: 350px;
}
</style>
<title>选择发放包</title>
</head>

<body>
    <div id="saper-container">
        <div id="saper-hd"></div>
        <div id="saper-bd">
            <div class="subfiled clearfix">
                <h2>选择发放包</h2>
            </div>
            
            <div id="table_left" class="table">
                    <!--表格具体内容-->
                    <div class="table-box">
                    
                        <div>
	                        <div id="ddd">
	                        <label>选择科室：</label>
	                            <select class="search_text" id="keshi">
				                                <c:if test="${tbDepartment.departmentId != null }">
				                                <option value="${tbDepartment.departmentId}">${tbDepartment.departmentName}</option>
				                                <option value="" >请选择</option>
				                                </c:if>
				                                <c:if test="${tbDepartment.departmentId == null }">
	                                            <option value="">请选择</option>
	                                            </c:if>
	                               				<c:if test="${alldeparts != null}">
				                            	<c:forEach items="${alldeparts}" var="pro">
				                            	<c:if test="${pro.departmentId!=15 && pro.departmentId!=tbDepartment.departmentId}">
				                                	<option value="${pro.departmentId}">${pro.departmentName}</option>
				                                </c:if>
				                                </c:forEach>
				                                </c:if>
	                            </select>
                            </div>
                            <div class="buttons"  id="ddd">
	                            <a href="javascript:;" class="sapar-btn sapar-btn-recom" id="chaxun">查询</a>
	                        </div>
	                        <div class="buttons" id="fff">
	                            <a href="javascript:;" class="sapar-btn sapar-btn-recom" id="queding">确定</a>
	                        </div>
                        </div>
	        <table id="t">
				<thead>
					<tr>
						<th><input type="checkbox" id="checkall" name="checkall"/></th>
						<!-- <th>申请流水</th> -->
						<th>包条码</th>
						<th>包名</th>
						<th>所属科室</th>
						<th>库存状态</th>

					</tr>
				</thead>
				<tbody>
				    <c:if test="${shenqingList == null || shenqingList == ''}">
				        <tr class="no-data product"><td colspan="10" style="color: red">暂时没有数据</td></tr>
				    </c:if>
					<c:if test="${shenqingList != null}">
						<c:forEach items="${shenqingList}" var="shenqing">
							<tr  data="${shenqing.packageTiaoma}">
								<td><input type="checkbox" name="key"
									value="${shenqing.packageTiaoma}"/></td>
								<td>${shenqing.packageTiaoma}</td>
								<td>${shenqing.packageName}</td>
								<td>${shenqing.tbPackageMuban.tbDepartment.departmentName}</td>
								<td>
									<c:if test="${shenqing.fafangLiushui != null && shenqing.baoRuku != 1}">已出库</c:if>
									<c:if test="${shenqing.fafangLiushui == null && shenqing.baoRuku == 1}">已入库</c:if>
								</td>
							</tr>
						</c:forEach>
					</c:if>
				</tbody>
			</table>
			</div>
			<div id="saper-ft">
			    <div id="kkpager"></div>
		    </div>
            </div>
        </div>
    </div>
    
</body>

<script type="text/javascript">

function isNullOrEmpty(strVal){
	strVal = strVal.replace(/(^\s*)|(\s*$)/g,"");
	if(strVal == '' || strVal == null || strVal == undefined){
		return true;
	}else{
		return false;
	}
}

function getParameter(name) { 
	var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)"); 
	var r = window.location.search.substr(1).match(reg); 
	if (r!=null) return unescape(r[2]); return null;
	}

$(function(){
	var shuliang=<%=request.getParameter("shuliang") %>;
	var shenqingliushui=<%=request.getParameter("shenqingliushui")%>;
	var keshi=$("#keshi").val();
	<%-- var totalPage = ${total};
	var pageNo = getParameter('pageIndex');
	if(!pageNo){
		pageNo = 1;
	}
	//生成分页
	//有些参数是可选的，比如lang，若不传有默认值
	kkpager.generPageHtml({
		pno : pageNo,
		//总页码
		total : totalPage,
		//链接前部
		hrefFormer : '${ctx}/wupingfafang/wupinshenqing',
		//链接尾部
		hrefLatter : '.do',
		getLink : function(n){
			return this.hrefFormer + this.hrefLatter + "?pageIndex="+n+"&searchTxt="+$(".search_text").val()+"&keshi="+keshi+"&shuliang="+shuliang+"&shenqingliushui="+shenqingliushui+"&fafangren=<%=request.getParameter("fafangren")%>";
		}
	}); --%>

	$("#checkall").click(function(){
		   if(this.checked){
		        $("input[name='key']").prop('checked', true)
		    }else{
		        $("input[name='key']").prop('checked', false)
		    }
	});
	
	$("#chaxun").click(function(){
		keshi=$("#keshi").val();
        window.location.href="${ctx}/wupingfafang/wupinshenqing.do?keshi="+keshi+"&shuliang="+shuliang+"&shenqingliushui="+shenqingliushui+"&fafangren=<%=request.getParameter("fafangren")%>";
	});
	
	$("#queding").click(function(){
		var btn=true;
		var chk_value=getSelRecord();
	    shuliang=<%=request.getParameter("shuliang") %>;
	    var index = parent.layer.getFrameIndex(window.name);
	    if(chk_value.length==0){
	    	layer.alert("请选择要发放的包");
	    	btn=false;
	    	return btn;
	    }
		if(chk_value.length!=shuliang){
			layer.alert("发放的包数量不等于要申请的包数量");
			btn=false;
			return btn;
		}
		$.ajax({
             type: "POST",
             url:"${ctx}/shenqing/wupingfafang.do?tiaoma="+chk_value.join()+"&shenqingliushui="+shenqingliushui+"&mingxi=0"+"&fafangren=<%=request.getParameter("fafangren")%>",
             data:$('#dataForm').serialize(),// 你的formid
             error: function(request) {
            	 	layer.alert("网络故障，请稍后再试!");
             },
             success: function(data) {
 	           	if(data.status=="true"){
	 	           	layer.alert("保存成功", function(){
	 	           		parent.layer.close(index);
           		    });
	 	       
 	           	}else{
 	           		 layer.msg(data.msg);
 	           	}
             }
        }); 
	});
});

function getSelRecord(){
	var chk_value =[];
	$('input[name="key"]:checked').each(function(){
		chk_value.push($(this).val()); 
	});
	return chk_value;
} 
function tongji(){
	var chk_value =[];
	$('input[name="key"]:checked').each(function(){
		chk_value.push($(this).val()); 
	});
	return chk_value;
} 

//接受条码枪的录入
function callbackPackData(data){
	var baoArr = data;//扫码传入
	var baoTmArr = [];//页面显示
    var wybao=[];//用来提示不可录入的包条码
	var btnArr=[];//用来与扫描的包比较
    $('input[name="key"]').each(function(){
    	baoTmArr.push($(this).val());
	});
    var bao=null;
    var baoTm=null;
    for(var i=0;i<baoArr.length;i++){
    	bao=baoArr[i];
    	for(var j=0;j<baoTmArr.length;j++){
    		baoTm=baoTmArr[j];
    		if(bao==baoTm){
    			$('input[name="key"]').each(function(){
    		    	if($(this).val()==bao){
    		    		$(this).prop('checked',true);
    		    	}
    			});
    		}else{
   	    		btnArr.push(baoTm);
    		}
    	}
    	if(btnArr.length==baoTmArr.length){
			wybao.push(bao);
    	}
    }
    if(wybao.length!=0){
		alert("不能进行操作的包:"+wybao);
	}
}

$(document).ready(function(){
	layer.open({
		  type: 2,
		  title: '发放扫码',
		  maxmin: true,
		  shadeClose: false, //点击遮罩关闭层
		  area : ['600px' , '380px'],
		  content: '${ctx}/page/wupinfafang/fafang_barcode.jsp'
		  });
	
});
</script>
</html> 